-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use GitHub app auth #13
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this, it seems like a much more sustainable way of authorising with github.
|
||
nunjucks.configure({ | ||
autoescape: true, | ||
watch: true, | ||
}); | ||
|
||
const ACCESS_TOKEN = process.env.GITHUB_PERSONAL_ACCESS_TOKEN; | ||
const httpServer = createServer(async (request, response) => { | ||
if (await OctokitApp.middleware(request, response)) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to abstract this out of the callback passed to createServer
into a named function, but that can come in a later PR.
90afc0f
to
89f953a
Compare
GitHub encourages the use of the GitHub App workflow when a system needs to interact with the GitHub API on its own behalf, rather than using personal access tokens which need to be regenerated on a regular basis. This library exposes the GitHub API in a way that's indended to be used for this workflow. See https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app for more information about authentication for GitHub apps, including when an application should authenticate as itself rather than as a user.
dd75872
to
0b3309b
Compare
This sets up the `App` instance and registers a generic set of webhooks that can be used by the Node HTTP server as middleware.
0b3309b
to
a1802a4
Compare
This setup iterates over all installations of the GitHub app and displays their repositories in the previously made table. Iterating over multiple installations rather than specifying it explicitly will allow us to support repositories we manage in other organisations by getting them to install Towtruck as a GitHub app in their organisation settings and granting access to the repositories that we maintain for them. However, currently we only want to support single-account installations. There doesn't seem to be a neat way to get the installation ID from an account name, so we will use `eachInstallation` to loop (hopefully once) and just take the first (hopefully only) element from `installations` so that we can have more meaningful template names in Nunjucks. We can enforce this one-installation approach through GitHub by configuring the app to be "Only on this account" when registering the app.
a1802a4
to
fb45cf4
Compare
GitHub encourages the use of the GitHub App workflow when a system needs to interact with the GitHub API on its own behalf, rather than using personal access tokens which need to be regenerated on a regular basis.
This PR provides a basic implementation using the GitHub App workflow to provide the list of repositories for organisations that have the app installed.